package com.axcbd.demo.config;

import org.springframework.context.annotation.Configuration;
import org.springframework.http.CacheControl;
import org.springframework.web.servlet.config.annotation.ResourceHandlerRegistry;
import org.springframework.web.servlet.config.annotation.WebMvcConfigurer;

import java.util.concurrent.TimeUnit;

@Configuration
public class WebConfig implements WebMvcConfigurer {

    @Override
    public void addResourceHandlers(ResourceHandlerRegistry registry) {
        registry.addResourceHandler("/video_backups/**")
                .addResourceLocations("file:video_backups/")
                .setCacheControl(CacheControl.maxAge(0, TimeUnit.SECONDS)); // 禁用缓存以便实时查看

        // 将 D:\work_station\fullstack\axcbd\front_end\demo\public\motion_frames\ 路径下的资源映射到 /images/**
        // 其中 "/images/**" 是访问的 URL 前缀，"/D:/work_station/fullstack/axcbd/front_end/demo/public/motion_frames/" 是实际的文件存储路径
        registry.addResourceHandler("/images/**").
                addResourceLocations("file:/D:/work_station/fullstack/axcbd/front_end/demo/public/motion_frames/");


    }
}